package com.lixiaoyi.emp.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author 李小毅
 * @Description
 * @Date 2022-05-12
 */
//@WebServlet(name = "/CreateCodeController",value = "/createCode")

@WebServlet("/createCode")
public class CreateCodeController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.生成验证码
        ValidateCode validateCode = new ValidateCode(200, 30, 4, 20);
        String codes = validateCode.getCode();
        //2.存储验证码信息
        HttpSession session = request.getSession();
        session.setAttribute("codes",codes);

        //输出到页面
        validateCode.write(response.getOutputStream());
    }



    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }


}
